package edu.sias.question.controller;

import edu.sias.common.core.controller.BaseController;
import edu.sias.common.core.domain.AjaxResult;
import edu.sias.common.core.page.TableDataInfo;


import edu.sias.question.domain.pojo.Question;
import edu.sias.question.domain.pojo.UserTopic;
import edu.sias.question.domain.vo.TopicVo;
import edu.sias.question.service.QuestionService;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 试题管理
 */
@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Autowired
    private QuestionService questionService;

    /**
     * 分页查询题库列表
     */
    @GetMapping("/list")
    public TableDataInfo findListByPage(Integer couseId,Integer catalogId) {
        startPage(); // 启动分页
         logger.info("分页查询题库列表");
        List<Question> list = questionService.findList(couseId,catalogId);
        return getDataTable(list); // 返回分页数据
    }
    /**
     * 用户端查询题库列表
     */
    @GetMapping("/user/list")
    public AjaxResult findUserListByPage(UserTopic userTopic) {
        List<TopicVo> list = questionService.findUserList(userTopic);
         return AjaxResult.success(list);
    }

    /**
     * 新增或更新题目
     */
    @ApiOperation("新增或更新题目")
    @PostMapping
    public AjaxResult addOrUpdate(@RequestBody Question question) throws IOException {
        questionService.addOrUpdate(question);
        return AjaxResult.success("操作成功");
    }

   /* *//**
     * 分页查询精选题库
     */
    @GetMapping("/classic/list")
    public TableDataInfo findClassicListByPage() {
        startPage();
        List<Question> list = questionService.findClassicList();
        return getDataTable(list);
    }
/*
根据公司 技术栈 职位 获取题目详细信息
 */

    /**
     * 将题目加入收藏
     */
    @ApiOperation("将题目加入收藏")
    @GetMapping("/updateClassic")
    public AjaxResult updateClassic(int id) {
        questionService.updateClassic(id);
        return AjaxResult.success("操作成功");
    }

    /**
     * 根据 ID 查询题目详情
     */
    @ApiOperation("根据 ID 获取题目详情")
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) throws IOException {
        return AjaxResult.success(questionService.getById(id));
    }

     /*
     根据题目id删除题目
      */
    @ApiOperation("根据题目id删除题目")
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id) throws IOException {
        questionService.deleteById(id);
        return AjaxResult.success("删除试题成功！");
    }
}
